package com.zw.cloud.tools.controller.ai;

import com.aliyuncs.CommonResponse;
import com.zw.cloud.tools.service.AliyunFaceAiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Base64;

@RestController
@RequestMapping("/ai/aliyun/face")
@Slf4j
public class AliyunFaceAiController {

    @Autowired
    private AliyunFaceAiService aliyunFaceAiService;


    @PostMapping
    //http://localhost:9040/ai/aliyun/face
    public boolean addFace(String id,String name,MultipartFile file)throws Exception{
        String image = Base64.getEncoder().encodeToString(file.getBytes());
        return aliyunFaceAiService.addFace(id,name,image);
    }

    @DeleteMapping
    //http://localhost:9040/ai/aliyun/face?id=&name=
    public boolean deleteFace(String id,String name){
        return aliyunFaceAiService.deleteFace(id, name);
    }

    @PostMapping("/recognizeFace")
    // 查找注册库中的人脸
    //http://localhost:9040/ai/aliyun/face/recognizeFace
    public CommonResponse recognizeFace(MultipartFile file) throws Exception{
        String image = Base64.getEncoder().encodeToString(file.getBytes());
        return aliyunFaceAiService.recognizeFace(image);
    }

    @PostMapping("/checkFace")
    //http://localhost:9040/ai/aliyun/face/checkFace
    //人脸属性识别 face_num  int  检测出来的人脸个数
    public String checkFace(MultipartFile file)throws Exception{
        String image = Base64.getEncoder().encodeToString(file.getBytes());
        return aliyunFaceAiService.checkFace(image);
    }

    @GetMapping
    //http://localhost:9040/ai/aliyun/face
    public CommonResponse listFace()throws Exception{
        return aliyunFaceAiService.listFace();
    }
}
